﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ArgosDesktop
{
	internal static class ExtensionMethods
	{

		public static string GetAssemblyFileVersion(this Assembly assembly)
		{
			AssertNotNull(assembly, "assembly");

			object[] arr = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
			if (null != arr && arr.Length > 0)
			{
				AssemblyFileVersionAttribute a = (AssemblyFileVersionAttribute)arr[0];
				return a.Version;
			}

			return null;
		}

		public static string GetAssemblyVersion(this Assembly assembly)
		{
			AssertNotNull(assembly, "assembly");

			return assembly.GetName().Version.ToString();
		}

		public static string GetCompanyName(this Assembly assembly)
		{
			AssertNotNull(assembly, "assembly");

			object[] arr = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
			if (null != arr && arr.Length > 0)
			{
				AssemblyCompanyAttribute a = (AssemblyCompanyAttribute)arr[0];
				return a.Company;
			}

			return null;
		}

		public static string GetProductName(this Assembly assembly)
		{
			AssertNotNull(assembly, "assembly");

			object[] arr = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
			if (null != arr && arr.Length > 0)
			{
				AssemblyProductAttribute a = (AssemblyProductAttribute)arr[0];
				return a.Product;
			}

			return null;
		}



		private static void AssertNotNull(object item, string name)
		{
			if (null == item)
			{
				throw new ArgumentNullException(name);
			}
		}

	}
}
